const s = {
  v: `
          attribute vec4 a_position;
          uniform mat4 mat;
          void main() {
              gl_Position = mat * a_position;
          }
      `,
  f: `
      void main() {
          gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
      }
      `,
}
// 得到着色器程序
const program = getProgram(gl, s)
// // 获取着色器程序中的变量
const a_position = gl.getAttribLocation(program, "a_position")
const mat = gl.getUniformLocation(program, "mat")
// //TODO 创建顶点数据
const positionData = new Float32Array([-0.5, -0.5, 0.5, -0.5, 0.0, 0.5])
// // 创建缓冲对象
const buffer = gl.createBuffer()
// // 绑定缓冲对象
gl.bindBuffer(gl.ARRAY_BUFFER, buffer)
// // 填充缓冲对象
gl.bufferData(gl.ARRAY_BUFFER, positionData, gl.STATIC_DRAW)
// // 配置变量
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0)
// // 启用变量
gl.enableVertexAttribArray(a_position)

let deg = 0
let translateX = -1
let scaleX = 0.1
// 动画循环
function animate() {
  deg += 0.01
  translateX += 0.01
  scaleX += 0.01

  if (translateX > 1) {
    translateX = -1
  }
  if (scaleX > 1.5) {
    scaleX = 0.1
  }
  const translate = getTranslateMatrix(translateX)
  const scale = getScaleMatrix(scaleX)
  const rotate = getRotataMatrix(deg)

  const matrix = mixMatrix(mixMatrix(translate, scale), rotate)

  gl.uniformMatrix4fv(mat, false, matrix)

  gl.drawArrays(gl.TRIANGLES, 0, 3)
  requestAnimationFrame(animate)
}
animate()
